package org.karelun.gef.actions;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.karelun.gef.editors.DiagramEditorInput;
import org.karelun.gef.helper.ConstantMessages;
import org.karelun.gef.helper.IDConstant;
import org.karelun.gef.helper.ImageResource;

public class CreateUseCaseEditorAction extends Action{
	
	private IWorkbenchWindow window;
	
	public CreateUseCaseEditorAction(IWorkbenchWindow window){
		this.window=window;
		setId(IDConstant.UseCaseEditAction_id);
		setActionDefinitionId(IDConstant.UseCaseEditAction_CMD_ID);
		setText(ConstantMessages.userCaseEditor_Text);
		setToolTipText(ConstantMessages.userCaseEditor_ToolTip);
		setImageDescriptor(ImageResource.getImageDesc(ImageResource.NEW_USERCASE_ACTION));
	}
	@Override
	public void run() {
		IPath path = Platform.getLocation();
		IEditorInput input=new DiagramEditorInput(path);
		IWorkbenchPage page = window.getActivePage();
		try {
			page.openEditor(input, IDConstant.UserCaseDiagramEditor_Id);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
}
